/*
 * Author: 黄荣基
 * Date: 2020-11-12 10:52:12
 * LastEditors: 黄荣基
 * LastEditTime: 2020-11-13 11:06:28
 */
// ./src/mixins/emitter.js
export default {
  methods: {
    dispatch(componentName, eventName, params) {
      let parent = this.$parent || this.$root,
        { name } = parent.$options;
      while (parent && (!name || name !== componentName)) {
        parent = parent.$parent;
        // eslint-disable-next-line prefer-destructuring
        if (parent) name = parent.$options.name;
      }
      // eslint-disable-next-line prefer-spread
      if (parent) parent.$emit.apply(parent, [eventName].concat(params));
    }
  }
};
